<template>

  <el-form :model="tableData" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-card class="box-card">
      <span>基本信息</span>
      <div class="text item">
        <el-form-item label="订单号">
          <el-input v-model="tableData.orderNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="申请时间">
          <el-input :value="getDate(tableData.addTime)" disabled></el-input>
        </el-form-item>

        <el-form-item label="订单状态" >
          <el-input v-model="tableData.statusString" disabled></el-input>
        </el-form-item>
        <el-form-item label="汽车总数量">
          <el-input v-model="tableData.carSumNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="融资经销商" >
          <el-input v-model="tableData.dealerName" disabled></el-input>
        </el-form-item>
        <el-form-item label="融资总金额(元)">
          <el-input :value="tableData.mortgageSumMoney| toFixed2" disabled></el-input>
           <span class="convertCurrency">{{tableData.mortgageSumMoney|convertCurrency}}</span>
        </el-form-item>
        <el-form-item label="待回款本金(元)">
          <el-input :value="tableData.needCapital| toFixed2" disabled></el-input>
           <span class="convertCurrency">{{tableData.needCapital|convertCurrency}}</span>
        </el-form-item>
        <el-form-item label="应打保证金金额(元)" >
          <el-input :value="tableData.deposit| toFixed2" disabled></el-input>
           <span class="convertCurrency">{{tableData.deposit|convertCurrency}}</span>
        </el-form-item>

      </div>
    </el-card>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>保证金信息</span>
      </div>
      <el-form-item label="保证金添加时间" >
        <el-input :value="getDate(tableData.cashDepositAddTime)"  disabled></el-input>
      </el-form-item>
      <el-form-item label="保证金凭证">
        <qiniu v-if='tableData.voucherPic!==null?true:false' :qiniuImage="tableData.voucherPics" :id="tableData.voucherPics.id" :canDelete="false"></qiniu>
      </el-form-item>
      <el-form-item label="经销商备注">
        <el-input v-model="tableData.remark" disabled></el-input>
      </el-form-item>
      <el-form-item label="保证金审核" prop="radio" style='marginTop:20px'>
        <el-radio v-model="tableData.isPass" :label="true" :disabled='dialogSendData.isAdd'>通过</el-radio>
        <el-radio v-model="tableData.isPass" :label="false" :disabled='dialogSendData.isAdd'>不通过</el-radio>
      </el-form-item>
      <el-form-item label="保证金审核备注" prop="reviewRemark">
        <el-input v-model="tableData.reviewRemark" :maxlength='100' :disabled='dialogSendData.isAdd'></el-input>
      </el-form-item>
      <el-form-item label="保证金审核人">
        <el-input v-model="tableData.auditPerson" disabled></el-input>
      </el-form-item>
      <el-form-item label="保证金审核时间" >
          <el-input :value="getDate(tableData.auditTime)" disabled></el-input>
      </el-form-item>


    </el-card>

    <el-form-item class='align'>
      <el-button type="primary" @click="resetForm('ruleForm')">返回</el-button>
      <el-button @click="submitForm('ruleForm')"  type="success" v-if='!dialogSendData.isAdd'>提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  import qiniu from '@/views/qiniu/upload';
   import {
    require,
    prop,
    decimalTwo
  } from '@/utils/rules.js' //表单验证规则
  import agentHttp from '@/utils/agentHttp.js'
  import { timestampToTime } from '@/utils/index.js'
  
  
  export default {
    data() {
      return {
        tableData: {
         audit:'',
         radio:false
        },
        rules: {
          radio :[require('保证金审核')],
          reviewRemark  :[require('保证金审核备注')]
        },
        radio: '1',
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate(valid => {
          if (valid) {
              const params = {
                  id:this.tableData.id ,//保证金id
                  isPass:this.tableData.isPass==1?true:false,
                  remark:this.tableData.reviewRemark, //保证金审核备注
              }
            console.dir(params)
              agentHttp.put(`adminApi/admin/mortgage_cash_deposit/audit`,params).then(res=>{
                if(res.success){
                  this.dialogSendData.dialogFormVisible = false;
                  this.$message.success(res.data||"提交成功");
                   this.$emit('Refresh',null); 
                }
              })

          } else {
            console.log("error submit!!");
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
        this.dialogSendData.dialogFormVisible = false;
      },
      initData(){
          agentHttp.get(`adminApi/admin/mortgage_cash_deposit/view/${this.id}`).then(res=>{
                if(res.success){
                    this.tableData = Object.assign({},res.data.order,this.tableData)  ;
                    if(this.tableData.voucherPic!=null){
                            this.tableData.voucherPics = {
                                id:'this.tableData.voucherPic',
                                image_uri: this.tableData.voucherPic.split(',').notempty()    //验车图片
                              }
                    }
                    this.tableData.isPass =  this.tableData.isPass==1?true:false
                    console.dir(this.tableData.isPass)
                }
          })
      },
      getDate(time){
        return timestampToTime(time)
      }
    },
    props: {
      dialogSendData: {
        type: Object
      },
      id:{
        type:Number
      }
    },
    mounted() {
      this.initData()
      // console.log(this.dialogSendData)
    },
    components: {
      qiniu
    }
  };

</script>

<style lang="scss" scoped>
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }

  .clearfix:after {
    clear: both;
  }

  .box-card {
    margin-top: 20px;
  }

  .align {
    margin: 50px auto 0;
    text-align: center;
  }

</style>

